<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="fourth.el.domain.Address" %>
<%@ page import="fourth.el.domain.User" %><%--
  Created by IntelliJ IDEA.
  User: wgy
  Date: 2019/10/26
  Time: 20:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL表达式的使用</title>
</head>
<body>
<%
    //向域中存数据
    pageContext.setAttribute("username", "张三");
    request.setAttribute("age", "20");
    session.setAttribute("gender", "男");
    application.setAttribute("address", "北京西二旗");


    //创建User对象
    Address address = new Address("中国", "上海");
    User user = new User("联盟", 18, "lianmeng@qq.com", address, "13999999999");
    pageContext.setAttribute("user", user);

%>
<h1>案例一：获取简单数据</h1>
<h4>使用脚本表达式</h4>
<%=pageContext.findAttribute("username")%><br/>
<%=pageContext.findAttribute("age")%><br/>
<%=pageContext.findAttribute("gender")%><br/>
<%=pageContext.findAttribute("address")%><br/>
<h4>使用EL表达式</h4>
${"username"}<br/>
${username}<br/>
${age}<br/>
${gender}<br/>
${address}<br/>
<h1>案例二：获取对象属性</h1>
${user.username}<br/>
${user.age}<br/>
${user.email}<br/>
${user.address.country}<br/>
${user.address.city}<br/>
${user.phone}<br/>

<h1>案例三：使用List和Map集合</h1>
<%
    List<String> cities = new ArrayList<String>();
    cities.add("北京");
    cities.add("上海");
    cities.add("杭州");
    cities.add("深圳");
    pageContext.setAttribute("cities", cities);

    Map<String, String> map = new HashMap<>();
    map.put("China", "中国");
    map.put("USA", "美国");
    map.put("UK", "英国");
    map.put("KOR", "韩国");
    map.put("11", "泰国");
    map.put("22", "朝鲜");
    pageContext.setAttribute("map", map);
%>

${cities[0]}<br/>
${cities[1]}<br/>
${cities[2]}<br/>
${cities[3]}<br/>
${cities[4]}<br/>
<hr/>
${map.China}
${map.USA}
${map.UK}
${map.KOR}

<br/>
${map['China']}
${map['USA']}
${map['UK']}
${map['KOR']}
${map['11']}
${map['22']}
<h1>empty空判断</h1>
${empty user?"没有登录":user.username}

<h1>EL表达式的隐式对象</h1>
上下文路径:${pageContext.request.contextPath}

</body>
</html>
